/**
 * 69. x 的平方根
 * https://leetcode.cn/problems/sqrtx/description/
 */
class Solution2 {
    public int mySqrt(int x) {
        if(x <= 0) return 0;
        long left = 1, right = x;
        while(left < right) {
            long mid = left + (right - left + 1) / 2;
            long tmp = mid * mid;
            if(tmp <= x) left = mid;
            else right = mid - 1;
        }
        return (int)left;
    }
}